package com.juhuixing.auth.server.controller;

import com.juhuixing.common.base.ResponseData;
import com.juhuixing.common.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述: 注销
 * @author: 刘猛
 * @date: 2019/2/20 16:59
 **/
@RestController
public class LogoutController {
    @Autowired
    private ConsumerTokenServices consumerTokenServices;

    @DeleteMapping(value = "/exit")
    public @ResponseBody
    ResponseData revokeToken(String access_token){
        ResponseData msg = new ResponseData();
        if (consumerTokenServices.revokeToken(access_token)){
            msg.setCode(StatusCode.SUCCESS_CODE);
            msg.setMessage("注销成功");
        }else {
            msg.setCode(StatusCode.FAILURE_CODE);
            msg.setMessage("注销失败");
        }
        return msg;
    }
}
